﻿/***************************************************************
 * 开发人员：网魂小兵@http://www.mozlite.com
 * 
 * 清楚过期日志服务。
 * 
 * 最后修改：2011-10-31
 * ************************************************************/
namespace Mozlite.Common
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Mozlite.Common.Configuration;

    /// <summary>
    /// 清楚过期日志服务。
    /// </summary>
    public class ClearExpiredLogTask : TaskBase
    {
        protected override void SetExecuteTime()
        {
            SetDayExecuteTime(4, 0, 0);
        }

        protected override void Action()
        {
            SiteDomains.Foreach(id =>
            {
                Logs.Clear(id, DateTime.Now.AddDays(-1.0 * SiteSettings.Default.LogExpiredDays));
            }, ex =>
            {
                Logs.Error("清理日志错误：", "Task Action", EventID.Tasks, ex, "ClearExpiredLogTask");
            });
        }

        public override bool Enabled
        {
            get { return true; }
        }

        public override ExecuteMode ExecuteMode
        {
            get { return Common.ExecuteMode.Day; }
        }
    }
}
